<template>
    <view>
        <!--#ifdef APP-PLUS-->
        <view class="lz-status_bar">
            <view class="lz-top_view"></view>
        </view>
        <!--#endif-->
        <view class="kaoshi-user">
            <view class="kaoshi-user-l" @tap="$openrul('/pages/auth/choiceSubject/index')">
                切换
                <view class="iconfont icon-weibiaoti"></view>
            </view>
            <view class="kaoshi-user-m">我的</view>
			<view v-if="$myConfig.mode != 3" class="kaoshi-user-right"></view>
			<!-- 微信授权和小程序授权不需要设置个人信息 -->
			<view v-if="$myConfig.mode == 3" class="kaoshi-user-right">
                <view class="iconfont icon-shezhi1" @tap="navTo('/pages/my/setting/index')"></view>
            </view>
        </view>
		<view v-if="$myConfig.mode == 3" class="kaoshi-user-top">
		            <view class="kaoshi-user-top-content">
		                <image class="kaoshi-user-top-content-image" :src="userinfo.user_id  ? user_info.avatar : static_media.kong"
		                      ></image>
		                <view class="kaoshi-user-top-title">
		                    <view v-if='userinfo.user_id == undefined' @tap="$openrul('/pages/auth/login/index')">请登录</view>
		                    <view v-else>
		                        {{userinfo.nickname}}
		                    </view>
		                </view>
		            </view>
		</view>
       <view v-else class="kaoshi-user-top">
            <view class="kaoshi-user-top-content">
                <image class="kaoshi-user-top-content-image" :src="userinfo.user_id  ? userinfo.avatarUrl : static_media.kong"
                      ></image>
                <view class="kaoshi-user-top-title">
                    <view v-if="userinfo.user_id == undefined" @tap="$openrul('/pages/auth/login/index')">
                        请登录
                    </view>
					<view v-else>{{userinfo.nickName}}</view>
                </view>
            </view>
        </view>
        <uni-list>
            <view @tap="navTo('/pages/my/collect/index')" hover-class="none">
                <uni-list-item title="我的收藏" :thumb="static_media.img01"></uni-list-item>
            </view>
            <view @tap="navTo('/pages/my/learn/index')" hover-class="none">
                <uni-list-item title="我的错题" :thumb="static_media.img02"></uni-list-item>
            </view>
            <view @tap="navTo('/pages/my/recording/index')" hover-class="none">
                <uni-list-item title="考试记录" :thumb="static_media.img03"></uni-list-item>
            </view>
        </uni-list>
    </view>
</template>

<script>
    import {mapState} from 'vuex'
    import uniList from '@/components/uni-list/uni-list.vue'
    import uniListItem from '@/components/uni-list-item/uni-list-item.vue'
    import Error from '@/core/untils/error/index';

    export default {
        data() {
            return {
				user_info:{},
            }
        },
        mounted() {
        },
        computed: {
            ...mapState(['subject', 'userinfo']),
            static_media() {
                return {
                    img01: '/static/img/user-icon1.png',
                    img02: '/static/img/user-icon3.png',
                    img03: '/static/img/user-icon4.png',
                    kong: this.$myConfig.localMedia + '/static/img/txk.png',
                    useravatar: this.$myConfig.interMedia + this.userinfo.avatar
                }
            }
        },
        components: {
            uniList,
            uniListItem,
        },
        onShow() {
			if (this.$myConfig.mode == 3 && this.userinfo.token) {
			    this.getUserInfo();
			}
        },
		onLoad(){
		},
        methods: {
			async getUserInfo() {
			    let res = await this.$myHttp.post({
			        url: this.$myHttp.urlMap.userInfo,
			        needLogin: true
			    })
			    if (res.code == 1) {
			        this.user_info = res.msg
			    }
			},
            //跳转前需要登录
            navTo(url) {
                if (this.$myUserLogin.getToken()) {
                    this.$openrul(url)
                } else {
                    Error.errorNotLoggedIn();
                }
            },
			//授权完毕后继续调用之前的方法
			nextOrder(data){
				
			},
			ifShow(data){
			    this.Shouquan=data
			},
        }
    }
</script>

<style>
    .lz-top_view {
        background: #3c7bfc;
    }

    page {
        background: #f6f6f6;
    }

    .kaoshi-user {
        color: #fff;
        display: flex;
        justify-content: space-between;
        line-height: 50px;
        background: #3c7bfc;
        padding: 0 16px;
    }

    .kaoshi-user-top {
        background: #3c7bfc;
    }

    .kaoshi-user .iconfont {
        font-size: 22px;
    }

    .kaoshi-user-l {
        width: 20%;
        display: flex;
        align-items: center;
        font-size: 16px;
    }

    .kaoshi-user-l .icon-weibiaoti {
        padding-left: 4px;
        font-size: 18px;
    }

    .kaoshi-user-m {
        flex: 1;
        text-align: center;
        font-size: 18px;
    }

    .kaoshi-user-right {
        display: flex;
        align-items: center;
        width: 66px;
        justify-content: flex-end;
    }

    .kaoshi-user-top-content {
        display: flex;
        width: 89%;
        margin: 0 auto;
        padding: 17px 0 35px;
        position: relative;
        height: 67px;
    }

    .kaoshi-user-top-content-image {
        width: 72px;
        height: 72px;
        border-radius: 50%;
        margin-right: 12px;
    }

    .kaoshi-user-top-title {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: space-between;
        color: #fff;
        font-size: 18px;
    }
</style>
